//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2021 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto/tree/main/CodeGenerator. DO NOT EDIT.

import SotoCore

/// Error enum for S3
public struct S3ErrorType: AWSErrorType {
    enum Code: String {
        case bucketAlreadyExists = "BucketAlreadyExists"
        case bucketAlreadyOwnedByYou = "BucketAlreadyOwnedByYou"
        case invalidObjectState = "InvalidObjectState"
        case noSuchBucket = "NoSuchBucket"
        case noSuchKey = "NoSuchKey"
        case noSuchUpload = "NoSuchUpload"
        case objectAlreadyInActiveTierError = "ObjectAlreadyInActiveTierError"
        case objectNotInActiveTierError = "ObjectNotInActiveTierError"
    }

    private let error: Code
    public let context: AWSErrorContext?

    /// initialize S3
    public init?(errorCode: String, context: AWSErrorContext) {
        guard let error = Code(rawValue: errorCode) else { return nil }
        self.error = error
        self.context = context
    }

    internal init(_ error: Code) {
        self.error = error
        self.context = nil
    }

    /// return error code string
    public var errorCode: String { self.error.rawValue }

    /// The requested bucket name is not available. The bucket namespace is shared by all users of the system. Select a different name and try again.
    public static var bucketAlreadyExists: Self { .init(.bucketAlreadyExists) }
    /// The bucket you tried to create already exists, and you own it. Amazon S3 returns this error in all AWS Regions except in the North Virginia Region. For legacy compatibility, if you re-create an existing bucket that you already own in the North Virginia Region, Amazon S3 returns 200 OK and resets the bucket access control lists (ACLs).
    public static var bucketAlreadyOwnedByYou: Self { .init(.bucketAlreadyOwnedByYou) }
    /// Object is archived and inaccessible until restored.
    public static var invalidObjectState: Self { .init(.invalidObjectState) }
    /// The specified bucket does not exist.
    public static var noSuchBucket: Self { .init(.noSuchBucket) }
    /// The specified key does not exist.
    public static var noSuchKey: Self { .init(.noSuchKey) }
    /// The specified multipart upload does not exist.
    public static var noSuchUpload: Self { .init(.noSuchUpload) }
    /// This operation is not allowed against this storage tier.
    public static var objectAlreadyInActiveTierError: Self { .init(.objectAlreadyInActiveTierError) }
    /// The source object of the COPY operation is not in the active tier and is only stored in Amazon S3 Glacier.
    public static var objectNotInActiveTierError: Self { .init(.objectNotInActiveTierError) }
}

extension S3ErrorType: Equatable {
    public static func == (lhs: S3ErrorType, rhs: S3ErrorType) -> Bool {
        lhs.error == rhs.error
    }
}

extension S3ErrorType: CustomStringConvertible {
    public var description: String {
        return "\(self.error.rawValue): \(self.message ?? "")"
    }
}
